package com.mindbook.vip.gawxchatinfo.controller.nostrum;

import com.mindbook.vip.gawxchatinfo.entity.nostrum.PrimaryLiverCancerTreatmentProgrammeToGroup;
import com.mindbook.vip.gawxchatinfo.service.nostrum.PrimaryLiverCancerTreatmentProgrammeToGroupService;
import com.mindbook.vip.gawxchatinfo.utils.crud.CrudUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @NAME: wxb
 * @DATE: 2022/8/9
 * @DESCRIPTION:
 **/
@Api("肝癌检查指导治疗方案与分组中间表")
@RestController
@RequestMapping("primaryLiverCancerTreatmentProgrammeToGroup")
public class PrimaryLiverCancerTreatmentProgrammeToGroupController {

    @Autowired private PrimaryLiverCancerTreatmentProgrammeToGroupService service;


    @PostMapping("/")
    @ApiOperation("新增")
    private Result add(PrimaryLiverCancerTreatmentProgrammeToGroup p){
        Integer add = service.add(p);

        CrudUtils.validateAddResult(add);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_ADD_SUCCESS.getMsg());
    }

    @ApiOperation("修改")
    @PutMapping("/")
    public Result put(PrimaryLiverCancerTreatmentProgrammeToGroup p){
        Integer integer = service.put(p);

        CrudUtils.validateAddResult(integer);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_UPDATE_SUCCESS.getMsg());
    }

    @DeleteMapping("/{programmeId}/{groupId}")
    @ApiOperation("删除")
    public Result del(@PathVariable Integer programmeId,@PathVariable Integer groupId){
        Integer integer = service.del(programmeId, groupId);

        CrudUtils.validateDeleteResult(integer);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_DELETE_SUCCESS.getMsg());
    }

    @GetMapping("/list")
    @ApiOperation("列表")
    public Result findAll(){
        List<PrimaryLiverCancerTreatmentProgrammeToGroup> all = service.findAll();

        return ResultUtils.genSuccessResult(all);
    }

    @GetMapping("/groupName/{groupName}")
    @ApiOperation("根据groupName查询治疗方案列表")
    private Result findByGroupName(@PathVariable String groupName){
        List byGroupName = service.findByGroupName(groupName);

        return ResultUtils.genSuccessResult(byGroupName);
    }


}
